package swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class SWTTableExample{

	public static void main(String[] args) {
		
		Display display = new Display();
		Shell shell = new Shell(display);
		
		shell.setLayout(new GridLayout());

		Table table = new Table(shell, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
		data.heightHint = 200;
		table.setLayoutData(data);

		TableColumn columnA = new TableColumn(table, SWT.NONE);
		columnA.setText("Name");
		
		TableColumn columnB = new TableColumn(table, SWT.NONE);
		columnB.setText("Phone");
		
		for (int i = 0 ; i<= 30 ; i++){
			TableItem item = new TableItem(table, SWT.NONE);
			item.setText (0, "User " +i );
			item.setText (1, Integer.toString((int)(Math.rint(Math.random()*1000))));
		}
		
		columnA.pack();
		columnB.pack();
		
		shell.pack();
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

}



